import mysql.connector

def execute_sql(db_config: dict, create_sql: str, insert_sql_batches: list) -> None:
    """在数据库中执行SQL"""
    conn = None
    try:
        conn = mysql.connector.connect(**db_config)
        cursor = conn.cursor()
        
        # 执行建表语句
        cursor.execute(create_sql)
        print(f"    已创建表: {create_sql.split()[5]}")
        
        # 执行分批插入语句
        total_batches = len(insert_sql_batches)
        if total_batches == 0:
            print("    没有数据需要插入")
            return
            
        for i, insert_sql in enumerate(insert_sql_batches, 1):
            cursor.execute(insert_sql)
            print(f"    已插入批次 {i}/{total_batches} ({cursor.rowcount} 行)")
        
        conn.commit()
        print(f"    成功插入 {total_batches} 批数据")
    except mysql.connector.Error as err:
        print(f"    数据库错误: {err}")
        if conn:
            conn.rollback()
    except Exception as e:
        print(f"    其他错误: {e}")
        if conn:
            conn.rollback()
    finally:
        if conn and conn.is_connected():
            cursor.close()
            conn.close()